package com.yang.server;

import com.yang.mapper.TaskMainMapper;
import com.yang.mapper.TaskReplacementMapper;
import com.yang.pojo.TaskMain;
import com.yang.pojo.TaskReplacement;
import com.yang.service.TaskMainService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author 杨天可
 * @Date 2021/3/30 14:31
 * @Version 1.0
 */
@Component("taskReplacementServerStart")
public class TaskReplacementServerStart extends Thread {

    private static final Logger log = LoggerFactory.getLogger(TaskReplacementServerStart.class);

    private  TaskReplacement taskReplacement;
    public void setTaskReplacement(TaskReplacement taskReplacement) {
        this.taskReplacement = taskReplacement;
    }

    @Resource
    TaskReplacementMapper taskReplacementMapper;
    @Resource
    TaskMainMapper taskMainMapper;

    //    @Override
    public void run() {

        try {
            //查找是否已添加消息，避免重复添加
            TaskMain byTaskId = taskMainMapper.findByTaskId(taskReplacement.getId());
            if (byTaskId == null) {
                log.info("提交补卡消息，任务id：" + taskReplacement.getId());
                TaskMain taskMain = new TaskMain();
                taskMain.setTaskType(0);
                taskMain.setTaskId(taskReplacement.getId());
                int insert = taskMainMapper.insert(taskMain);

                if (insert > 0) {
                    log.info("提交补卡消息已提交，任务id：" + taskReplacement.getId());
                }

            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
}
